package ZhengZe;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExerMain
{
	public static void main(String[] args)
	{
		System.out.println("====");
		String regex = "\\$\\{(\\w+)\\}";
		String input = " ${name}在${stYear}-->${edYear}学期中,学习特别的刻苦,成绩优异,特发此状${deng}等奖;教务处发";
//		定义一个Map，并设置泛型为String
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "张三");
		map.put("stYear", "2018");
		map.put("edYear", "2019");
		map.put("deng", "一");
		hight(regex, input, map);
		coaa();
	}

	private static void hight(String regex, String input, Map<String, String> map)
	{
		/*用pattern.compile();将正则表达式编译到模板中 */
		Pattern pa = Pattern.compile(regex);
		//创建匹配给定输入与此模式的匹配器
		Matcher ma = pa.matcher(input);
		//ma.matches();尝试将整个区域与模型匹配
		StringBuffer sb = new StringBuffer();
		//通过find()方法来逐个寻找与模板相匹配
		while (ma.find())
		{
			System.out.println("我找到了" + ma.group(1));
			String key = ma.group(1);
			if (map.containsKey(key))
			{
				ma.appendReplacement(sb, map.get(key));
			}
		}
		ma.appendTail(sb);
		System.out.println(sb);
//		System.out.println(ma.matches());
	}

	public static void coaa()
	{
		Pattern a = Pattern.compile(".");
		Matcher b = a.matcher("a");
		Boolean ab = b.matches();
		System.out.println(ab);
	}
}
